package com.deer.wms.base.system.web.bill;

import com.deer.wms.base.system.model.bill.BillInSapAccountDetailCriteria;
import com.deer.wms.base.system.model.bill.BillInSapAccountDetailDto;
import com.deer.wms.base.system.service.bill.BillInSapAccountDetailService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 过账记录
 * @author 李帅辰
 * @date 2021/6/22 12:35
 */
@Controller
@RequestMapping("/in/billInSapAccount")
public class BillInSapAccountDetailController extends BaseController {

    private String prefix = "in/billInSapAccount";

    @Autowired
    private BillInSapAccountDetailService billInSapAccountDetailService;
  /*  *//**
     * 导出列表
     *//*
    @RequiresPermissions("in:billInSap:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam  String ids) {
        List<BillInSapAccountDetailDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            BillInSapAccountDetailCriteria b=new BillInSapAccountDetailCriteria();
            b.setBillInSapAccountLogDetailId(Integer.parseInt(s));
            List<BillInSapAccountDetailDto> billInSapAccountDetailDtos = billInSapAccountDetailService.fingBillInSapAccountDetailDtoList(b);
            for (BillInSapAccountDetailDto a:billInSapAccountDetailDtos
            ) {
                byIds.add(a);
            }


        }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<BillInSapAccountDetailDto> util = new ExcelUtil<BillInSapAccountDetailDto>(BillInSapAccountDetailDto.class);
        return util.exportExcel(byIds, "Sap单据");
    }
*/
    //打印
    @RequestMapping("print")
    public String print(@RequestParam String ids, Model model) {
        List<BillInSapAccountDetailDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
             ) {
            BillInSapAccountDetailCriteria b=new BillInSapAccountDetailCriteria();
            b.setBillInSapAccountLogDetailId(Integer.parseInt(s));
            List<BillInSapAccountDetailDto> billInSapAccountDetailDtos = billInSapAccountDetailService.fingBillInSapAccountDetailDtoList(b);
            for (BillInSapAccountDetailDto a:billInSapAccountDetailDtos
                 ) {
                byIds.add(a);
            }


        }


        model.addAttribute("byids", byIds);


        return prefix + "/print";
    }

    @RequiresPermissions("in:billInSapAccount:view")
    @GetMapping()
    public String billInSapAccount()
    {
        return prefix + "/billInSapAccount";
    }

    @GetMapping("/detail")
    public String detail() {
        return prefix + "/billInSapAccountDetail";
    }


    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(BillInSapAccountDetailCriteria billInSapAccountDetailCriteria) {
        startPage();
        List<BillInSapAccountDetailDto> billInSapAccountDetailDtos = billInSapAccountDetailService.fingBillInSapAccountDetailDtoList(billInSapAccountDetailCriteria);
        return getDataTable(billInSapAccountDetailDtos);
    }

    @PostMapping("/findBillInSapAccountDetailDtoById")
    @ResponseBody
    public BillInSapAccountDetailDto findBillInSapAccountDetailDtoById(Integer billInSapAccountDetailId) {
        return billInSapAccountDetailService.findBillInSapAccountDetailDtoById(billInSapAccountDetailId);
    }


    /**
     * 导出列表
     */
    @RequiresPermissions("in:billInSapAccount:partExcel")
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam  String ids) {
        List<BillInSapAccountDetailDto> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            BillInSapAccountDetailCriteria b=new BillInSapAccountDetailCriteria();
            b.setBillInSapAccountDetailId(Integer.parseInt(s));
            List<BillInSapAccountDetailDto> billInSapAccountDetailDtos = billInSapAccountDetailService.fingBillInSapAccountDetailDtoList(b);
            for (BillInSapAccountDetailDto a:billInSapAccountDetailDtos
            ) {
                byIds.add(a);
            }


        }
        ExcelUtil<BillInSapAccountDetailDto> util = new ExcelUtil<BillInSapAccountDetailDto>(BillInSapAccountDetailDto.class);
        return util.exportExcel(byIds, "SAP过账记录报表");
    }
    /**
     * 导出列表
     */
    @RequiresPermissions("in:billInSapAccount:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BillInSapAccountDetailCriteria billInSapAccountDetailCriteria) {
        List<BillInSapAccountDetailDto> billInSapAccountDetailDtos = billInSapAccountDetailService.fingBillInSapAccountDetailDtoList(billInSapAccountDetailCriteria);
        ExcelUtil<BillInSapAccountDetailDto> util = new ExcelUtil<BillInSapAccountDetailDto>(BillInSapAccountDetailDto.class);
        return util.exportExcel(billInSapAccountDetailDtos, "SAP过账记录报表");
    }



}
